package com.product.trace.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.product.common.annotation.Log;
import com.product.common.core.controller.BaseController;
import com.product.common.core.domain.AjaxResult;
import com.product.common.enums.BusinessType;
import com.product.trace.domain.ProductRetail;
import com.product.trace.service.IProductRetailService;
import com.product.common.utils.poi.ExcelUtil;
import com.product.common.core.page.TableDataInfo;

/**
 * 商品零售详情Controller
 *
 * @author wanghui
 * @date 2022-08-23
 */
@RestController
@RequestMapping("/trace/productretail")
public class ProductRetailController extends BaseController {
    @Autowired
    private IProductRetailService productRetailService;

    /**
     * 查询商品零售详情列表
     */
    @PreAuthorize("@ss.hasPermi('trace:productretail:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProductRetail productRetail) {
        startPage();
        List<ProductRetail> list = productRetailService.selectProductRetailList(productRetail);
        return getDataTable(list);
    }

    /**
     * 导出商品零售详情列表
     */
    @PreAuthorize("@ss.hasPermi('trace:productretail:export')")
    @Log(title = "商品零售详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProductRetail productRetail) {
        List<ProductRetail> list = productRetailService.selectProductRetailList(productRetail);
        ExcelUtil<ProductRetail> util = new ExcelUtil<ProductRetail>(ProductRetail.class);
        util.exportExcel(response, list, "商品零售详情数据");
    }

    /**
     * 获取商品零售详情详细信息
     */
    @PreAuthorize("@ss.hasPermi('trace:productretail:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return AjaxResult.success(productRetailService.selectProductRetailById(id));
    }

    /**
     * 新增商品零售详情
     */
    @PreAuthorize("@ss.hasPermi('trace:productretail:add')")
    @Log(title = "商品零售详情", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProductRetail productRetail) {
        return toAjax(productRetailService.insertProductRetail(productRetail));
    }

    /**
     * 修改商品零售详情
     */
    @PreAuthorize("@ss.hasPermi('trace:productretail:edit')")
    @Log(title = "商品零售详情", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProductRetail productRetail) {
        return toAjax(productRetailService.updateProductRetail(productRetail));
    }

    /**
     * 删除商品零售详情
     */
    @PreAuthorize("@ss.hasPermi('trace:productretail:remove')")
    @Log(title = "商品零售详情", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids) {
        return toAjax(productRetailService.deleteProductRetailByIds(ids));
    }
}
